package com.wanxi.controller;

import com.wanxi.dto.ResultDTO;
import com.wanxi.service.ManagerService;
import com.wanxi.vo.ManagerVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
/**
 * @author Chengbo Zhang
 */
@RestController
@RequestMapping("/admin/manager")
@CrossOrigin(origins = "http://localhost:8081")
@Api(tags = "管理员管理",value = "管理员信息操作接口")
public class ManagerController {
    @Autowired
    ManagerService managerService;

    @GetMapping("/findAll")
    @ApiOperation(value = "管理员全查",response = ResultDTO.class,httpMethod = "GET")
    public ResultDTO findAllManager(){
        return managerService.findAllManager();
    }

    @PutMapping("/add")
    @ApiOperation(value = "管理员添加",response = ResultDTO.class,httpMethod = "PUT")
    @PreAuthorize("hasAuthority('insertManager')")
    public ResultDTO addManager(@ApiParam ManagerVO managerVO){
        return managerService.addManager(managerVO);
    }

    @PostMapping("/findById")
    @ApiOperation(value = "管理员单查",response = ResultDTO.class,httpMethod = "POST")
    public ResultDTO findManagerById(ManagerVO managerVO){
        return managerService.findManagerById(managerVO);
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "管理员删除",response = ResultDTO.class,httpMethod = "DELETE")
    @PreAuthorize("hasAuthority('deleteManager')")
    public ResultDTO deleteManager(ManagerVO managerVO){
        return managerService.deleteManager(managerVO);
    }

    @GetMapping("/findBySome")
    @ApiOperation(value = "管理员模糊查询",response = ResultDTO.class,httpMethod = "GET")
    public ResultDTO findManagerBySome(ManagerVO managerVO){
        return managerService.findManagerBySome(managerVO);
    }

    @PostMapping("/updateEnable")
    @PreAuthorize("hasAuthority('updateManager')")
    @ApiOperation(value = "管理员状态修改",response = ResultDTO.class,httpMethod = "POST")
    public ResultDTO updateManagerEnable(ManagerVO managerVO){
        return managerService.updateEnable(managerVO);
    }

    @PostMapping("/update")
    @PreAuthorize("hasAuthority('updateManager')")
    @ApiOperation(value = "管理员信息修改",response = ResultDTO.class,httpMethod = "POST")
    public ResultDTO updateManagerById(ManagerVO managerVO){
        return managerService.updateById(managerVO);
    }

    @PostMapping("/updatePassword")
    @ApiOperation(value = "管理员修改密码",response = ResultDTO.class,httpMethod = "POST")
    public ResultDTO updateManagerPassword(ManagerVO managerVO){
        return managerService.updatePassword(managerVO);
    }
}
